package com.jy.modules.cims.component.image.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.common.sysUtils.CollectionsUtils;
import com.jy.modules.cims.common.sysUtils.SearchParamUtil;
import com.jy.modules.cims.common.sysUtils.SimpleStringUtils;
import com.jy.modules.cims.common.sysUtils.SpringContextUtils;
import com.jy.modules.cims.component.image.TransferImagesDao;
import com.jy.modules.cims.data.dao.ImgurlDao;
import com.jy.modules.cims.data.dto.ImgurlDto;

/**
 * @description AddQueueService
 * @author shengzhoutao
 * @date 2015-09-29
 */
@Component
public class AddWaitDealQueueService {
	private static Logger logger = LoggerFactory.getLogger(AddWaitDealQueueService.class);

	@Autowired
	private ImgurlDao imgurlDao;

	@Autowired
	private SpringContextUtils springContextUtils;

	/**
	 * @description 放数据队列
	 * @return
	 */
	public int add() {
		try {
			ImgurlDto searchImgurlDto = new ImgurlDto();
			searchImgurlDto.setEachStatus(CimsConstant.LOAN_EACH_STATUS_URL);
			List<ImgurlDto> imgurlDtoList = imgurlDao.getPendingTransImgurl(SearchParamUtil.getSearchParam(searchImgurlDto));

			TransferImagesDao transferImagesDao = springContextUtils.getBean(TransferImagesDao.class);
			int successCount = transferImagesDao.insertQueue(imgurlDtoList);
			return successCount;
		} catch (Exception e) {
			logger.error(e.getMessage());
		}

		return 0;
	}

	/**
	 * 
	 * @param dealCode
	 * @param contractNoList
	 * @return
	 */
	public int add(String dealCode, List<String> contractNoList) {
		try {
			ImgurlDto searchImgurlDto = new ImgurlDto();
			searchImgurlDto.setEachStatus(CimsConstant.LOAN_EACH_STATUS_URL);
			if (SimpleStringUtils.hasText(dealCode)) {
				searchImgurlDto.setDealCode(dealCode);
			}
			if (CollectionsUtils.isNotEmpty(contractNoList)) {
				searchImgurlDto.setContractNoList(contractNoList);
			}
			List<ImgurlDto> imgurlDtoList = imgurlDao.getPendingTransImgurl(SearchParamUtil.getSearchParam(searchImgurlDto));

			TransferImagesDao transferImagesDao = springContextUtils.getBean(TransferImagesDao.class);
			int successCount = transferImagesDao.insertQueue(imgurlDtoList);
			
			return successCount;
		} catch (Exception e) {
			logger.error(e.getMessage());
		}

		return 0;
	}

}
